import facecat from "facecat"
import facecat_ws from "facecat_ws"
/*
* 点击方法
* view:视图
* firstTouch:是否第一次触摸
* firstPoint:第一次触摸的坐标
* secondTouch:是否第二次触摸
* secondPoint:第二次触摸的坐标
* clicks:点击次数
*/
let onClick = function (view, firstTouch, firstPoint, secondTouch, secondPoint, clicks) {
    facecat.onClickDefault(view, firstTouch, firstPoint, secondTouch, secondPoint, clicks);
};

/*
* 触摸开始方法
* view:视图
* firstTouch:是否第一次触摸
* firstPoint:第一次触摸的坐标
* secondTouch:是否第二次触摸
* secondPoint:第二次触摸的坐标
*/
let onTouchBegin = function (view, firstTouch, firstPoint, secondTouch, secondPoint) {
    facecat.onTouchBeginDefault(view, firstTouch, firstPoint, secondTouch, secondPoint);	
};

/*
* 触摸移动方法
* view:视图
* firstTouch:是否第一次触摸
* firstPoint:第一次触摸的坐标
* secondTouch:是否第二次触摸
* secondPoint:第二次触摸的坐标
*/
let onTouchMove = function (view, firstTouch, firstPoint, secondTouch, secondPoint) {
	facecat.onTouchMoveDefault(view, firstTouch, firstPoint, secondTouch, secondPoint);	
};

/*
* 触摸结束方法
* view:视图
* firstTouch:是否第一次触摸
* firstPoint:第一次触摸的坐标
* secondTouch:是否第二次触摸
* secondPoint:第二次触摸的坐标
*/
let onTouchEnd = function (view, firstTouch, firstPoint, secondTouch, secondPoint) {
	facecat.onTouchEndDefault(view, firstTouch, firstPoint, secondTouch, secondPoint);	
};

let gPaint = new facecat.FCPaint();
let that = null;
// index.js
// 获取应用实例
const app = getApp()
Page({
  data: {
    canvasWidth:0,
    canvasHeight:0,
    facecatStyle:"",
    facecatContent:"",
    facecatFocus:false
  },
  bindInputChange: function(e) {  
    if(gPaint.editingTextBox){
        gPaint.editingTextBox.text = e.detail.value;
        facecat.invalidateView(gPaint.editingTextBox);
        gPaint.editingTextBox = null;
        gPaint.app.setData({
            facecatStyle: "position:absolute;left:0px;top:0px;width:0px;height:0px;display:none;", 
            facecatFocus:false,
            facecatContent:""
         })
    }
  },
  touchStartCanvas: function (e) {
    facecat_ws.handleTouchStart(gPaint, e, onTouchBegin);
  },touchMoveCanvas: function (e) {
    facecat_ws.handleTouchMove(gPaint, e, onTouchMove);
  },touchEndCanvas: function (e) {
    facecat_ws.handleTouchEnd(gPaint, e, onTouchEnd, onClick);
  },
  onLoad() {
      that = this;
    wx.createSelectorQuery().select('#myCanvas').fields({ node: true, size: true }).exec((cres) => {   
        wx.getSystemInfo({
            success: function(res) {
                that.setData({
                    canvasWidth: res.windowWidth,  
                    canvasHeight: res.windowHeight
                 })
                cres[0].width = res.windowWidth;
                cres[0].height = res.windowHeight;
            }
        });   
        gPaint.defaultUIStyle = "dark";
        facecat_ws.scaleCanvas(gPaint, cres);
        let xml = `<?xml version="1.0" encoding="UTF-8"?>
        <html xmlns="facecat">
              <head>
            </head>
            <body>
                <div dock="fill">
                    <input type="button" name="Button" text="Button" cornerradius="10" size="50%,50%" location="25%,25%" backcolor="rgb(219,68,83)" />
                </div>
            </body>
        </html>`;  
	    facecat_ws.renderFaceCatWeChat(gPaint, xml, that);
    })
  }
})
